﻿
using System.Drawing;
using System.Drawing.Imaging;

namespace tjb.Barcode
{
    /// <summary>
    /// 条码生成
    /// </summary>
    public class Code128C
    {

        /// <summary>
        /// 生成条码
        /// <para>Code128C
        /// </para>
        /// </summary>
        /// <param name="BarString">条码模式字符串</param>
        /// <param name="Height">生成的条码高度</param>
        /// <returns>条码图形</returns>
        public static Bitmap KiCode128C(string BarString, int Height)
        {
            Bitmap b = new Bitmap(BarString.Length, Height, PixelFormat.Format24bppRgb);
            try
            {

                char[] cs = BarString.ToCharArray();

                for (int i = 0; i < cs.Length; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        if (cs[i] == 'b')
                        {
                            b.SetPixel(i, j, Color.Black);
                        }
                        else
                        {
                            b.SetPixel(i, j, Color.White);
                        }
                    }
                }

                return b;
            }
            catch
            {
                return null;
            }
        }


    }
}
